﻿namespace UsefulTools.ExtensionMethods
{
    using System;
    using System.ComponentModel;
    using System.Linq.Expressions;

    public static class ComponentModel
    {

        public static string PropertyName<T>(this Expression<Func<T>> propertyExpression)
        {
            var memberExpression = (MemberExpression) propertyExpression.Body;
            return memberExpression.Member.Name;
        }
        public static string PropertyName<Param, T>(this Expression<Func<Param, T>> propertyExpression)
        {
            var memberExpression = (MemberExpression) propertyExpression.Body;
            return memberExpression.Member.Name;
        }



        public static bool PropertyChanged<T>(
            this PropertyChangedEventArgs e, Expression<Func<T>> propertyExpression)
        {
            return e.PropertyName == PropertyName(propertyExpression);
        }
 
    }
}